<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
		"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>

	<title>_Widget.destroy() unit test</title>

	<script type="text/javascript" src="../../dojo/dojo.js" djConfig="isDebug: true, parseOnLoad: true"></script>
	<script type="text/javascript">
		dojo.require("doh.runner");
		dojo.require("dijit._Widget");

		var obj = {
			foo: function(){
				// summary: empty function that we connect to
			}
		};

		// Number of times foo was called while TestWidget existed
		var calls = 0;

		dojo.declare("dijit.TestWidget", dijit._Widget, {
			postCreate: function(){
				// Rather odd call to this.connect() For testing the connections are dropped on destroy()
				this.connect(obj, "foo", function(){
					calls++;
				});
			}
		});

		var w;

		dojo.addOnLoad(function(){
			doh.register("dijit._Widget",
				[
					{
						name: "create",
						runTest: function(t){
							w = new dijit.TestWidget({id: "w1"}, "w1");

							doh.t(dijit.byId("w1"), "widget in registry");

							// since there's no template, the widget just points to the srcNodeRef
							doh.is(w.domNode, dojo.byId("w1"), "srcNodeRef read in");

							// test the connection
							doh.is(0, calls, "foo() not called yet");
							obj.foo();
							doh.is(1, calls, "foo() called");
						}
					},
					{
						name: "destroy",
						runTest: function(t){
							w.destroy();

							doh.f(dijit.byId("w1"), "widget no longer in registry");

							// test the connection was destroyed
							calls = 0;
							obj.foo();
							doh.is(0, calls, "connection was deleted");

							// test the DOM node was removed
							doh.f(dojo.byId("w1"), "DOM Node removed");
						}
					},
					{
						name: "destroy(true)  (preserving DOM node)",
						runTest: function(t){
							w = new dijit.TestWidget({id: "w2"}, "w2");

							doh.t(dijit.byId("w2"), "widget in registry");
							w.destroy(true);

							doh.f(dijit.byId("w2"), "widget no longer in registry");

							// test the DOM node *wasn't* removed
							doh.t(dojo.byId("w2"), "DOM Node left");
						}
					}

				]
			);
			doh.run();
		});

	</script>
</head>
<body class="claro">

	<div id="w1"></div>
	<div id="w2"></div>
</body>
</html>
